<?php
session_start();
require('../conn.php');
require('../functions.php');
require('admin.php');
$page=$_GET['page'];
if(is_numeric($page)==false){
	$page=1;
}else{
	$page=$page+1;
}


$state=guolv($_GET['state']);
$id=guolv($_GET['id']);
$uid=guolv($_GET['uid']);
$money=guolv($_GET['money']);
$sx1=guolv($_GET['sx1']);
$day=date("Y-m-d",time());

//拒绝支付
if($state==2 && is_numeric($id)){
	$mysql->execute("update `txdata` set `state`=2 where `id`='{$id}'");
	//金币返还
	$mysql->execute("update `userdata` set `money`=`money`+'{$money}' where `id`='{$uid}'");
	echo "<script>alert('操作成功，金钱已返还到账户');location.href='txlist0.php'</script>";
	exit;
}

//确认支付
if($state==1 && is_numeric($uid)){
	//提成处理
	if(is_numeric($sx1)){
		$sx1_money=$money*($config['tc']/100);//1级上线提成
		$mysql->execute("update `userdata` set `money`=`money`+{$sx1_money},`money_all`=`money_all`+{$sx1_money},`money_xia`=`money_xia`+{$sx1_money} where `id`='{$sx1}'");//结算上线		
		//写入状态
		$arr_tx=array(
			//'id'=>null,
			'uid'=>$sx1,
			'aid'=>'',
			'title'=>"下线会员ID：{$uid}提现分成奖励",
			'long'=>'#',
			'money'=>$sx1_money,
			'ip'=>'',
			'day'=>$day,
			'time'=>date("Y-m-d H:i",time()),
		);
		$value=arr2s($arr_tx);
		$mysql->query("insert into `refererdata` {$value}");
	}
	$mysql->execute("update `txdata` set `state`=1 where `id`='{$id}'");
	echo "<script>alert('操作成功');location.href='txlist0.php'</script>";
	exit;
}
?>

<?php include('head.php')?>    

    <div class="container-fluid">
        
        <div class="row-fluid">
		<?php
		include('left.php');
		?>
<div class="span9">
            <h1 class="page-title">等待提现</h1>
		
<div class="well">
    <div id="myTabContent" class="tab-content">
      <div class="tab-pane active in" id="home">
		<div class="well">
<div class="pull-right">
<a href="outexcel.php" target="_blank" class="btn btn-primary">批量支付</a>
<button class="btn"><a href="txlist0.php">首页</a></button>
<button class="btn"><a href="?page=<?php echo $page?>">下一页</a></button>
</div>			
    <table class="table">
      <thead>
        <tr>
		  <th>申请时间</th>
		  <th>用户ID</th>
		  <th>师傅ID</th>
		  <th>真实姓名</th>
		  <th>支付宝</th>
		  <th>提现金额</th>
		  <th>操作支付</th>
        </tr>
      </thead>
      <tbody>
<?php
$row=$mysql->query("select * from `txdata` where `state`=0 order by `id` desc");
$row_tx=page_array(50,$page,$row,0);
	  foreach($row_tx as $v_tx){
		$time=date("Y-m-d H:i",$v_tx['time']);
print <<<table
        <tr>
		  <td>{$time}</td>
		  <td>{$v_tx['uid']}</td>
		  <td>{$v_tx['sx1']}</td>
		  <td>{$v_tx['realname']}</td>
		  <td>{$v_tx['alipay']}</td>
		  <td>{$v_tx['money']}</td>
		  <td>
		    <a class="btn" href="?state=1&id={$v_tx['id']}&money={$v_tx['money']}&uid={$v_tx['uid']}&sx1={$v_tx['sx1']}">确认</a>
			<a class="btn" href="?state=2&id={$v_tx['id']}&money={$v_tx['money']}&uid={$v_tx['uid']}&sx1={$v_tx['sx1']}">拒绝</a>
		  </td>
        </tr>
table;

	  }
	  ?>  
      </tbody>
    </table>
</div>
      </div>
      <div class="tab-pane fade" id="profile">
      </div>
  </div>

</div>

        </div>
    </div>
    

    
    <footer>
        <hr>
        
        <p class="pull-right"><!--power by right--></p>
        
        
        <p><!--power by --></p>
    </footer>
    

    

    <!-- Le javascript
    ================================================== -->
    <!-- Placed at the end of the document so the pages load faster -->
    <script src="lib/bootstrap/js/bootstrap.js"></script>
	


  </body>
</html>


